﻿using System;

using Sustainalytics.Utils;

namespace Sustainalytics.Portfolios.BL.Model
{
    using Sustainalytics.Entities;

    public class PortfolioModel : PortfolioBaseModel
    {
        internal PortfolioModel(
            Guid id, 
            string name, 
            PortfolioSharingStatus sharingStatus, 
            PortfolioUserClaims userInformation)
            : base(id, name, sharingStatus, userInformation)
        {
            this.DateModified = DateTime.Today;
        }

        public DateTime DataCreated { get; private set; }

        public DateTime? DateModified { get; set; }

        public string NameLowercase
        {
            get
            {
                return string.IsNullOrEmpty(this.Name) ? string.Empty : this.Name.ToLowerInvariant();
            }
        }

        public int SecuritiesCount { get; set; }

        public static PortfolioModel AddNewPortfolio(
            string name, 
            PortfolioSharingStatus sharingStatus, 
            PortfolioUserClaims userInformation)
        {
            var portfolio = new PortfolioModel(Guid.NewGuid(), name, sharingStatus, userInformation)
                                {
                                    DataCreated =
                                        DateTime
                                        .Today, 
                                    DateModified =
                                        DateTime
                                        .Today
                                };
            return portfolio;
        }
    }
}